﻿using System;
using System.Linq;
using UniMana.Utils.Controls;
using UniMana.Data;
using UniMana.Utils.Configs;

namespace UniMana.Data
{
    public class Student_CheckListInfo
    {
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();        

        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }

        public Training_Student_Checklist Properties
        {
            get { return m_bds.Current as Training_Student_Checklist; }
        }

        public Student_CheckListInfo(string nTrainingStudentKey = DefaultConfig.EMPTY_GUID)
        {
            var Iquery = m_data.m_DCSave.Training_Student_Checklists.Where(p => p.Training_StudentKey == Guid.Parse(nTrainingStudentKey));
            m_bds.DataSource = Iquery;
            var Row = Iquery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Training_Student_Checklist();
                Row.Training_StudentKey = Guid.Parse(nTrainingStudentKey);
                m_bds.Add(Row);
                m_bds.MoveLast();
            }
        }
    }
}
